import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

class ChatNetImage extends StatelessWidget {
  final String imageUrl;
  final double? radius;
  final BoxFit? fit;
  final double? width;
  final double? height;

  const ChatNetImage({
    Key? key,
    required this.imageUrl,
    this.radius = 0.0,
    this.fit = BoxFit.cover,
    this.width = 40,
    this.height = 40,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (imageUrl.isNotEmpty) {
      return SizedBox(
        width: width,
        height: height,
        child: ClipRRect(
          borderRadius: BorderRadius.circular(radius ?? 0),
          child: CachedNetworkImage(
            imageUrl: imageUrl,
            fit: fit,
            placeholder: (context, url) => Image.asset(
              'images/ic_avatar_def_boy.png',
            ),
            errorWidget: (context, url, error) => Image.asset(
              'images/ic_avatar_def_boy.png',
            ),
          ),
        ),
      );
    } else {
      return SizedBox(
          width: width,
          height: height,
          child: ClipRRect(
              borderRadius: BorderRadius.circular(radius ?? 0),
              child: Image.asset(
                'images/ic_avatar_def_boy.png',
              )));
    }
  }
}
